package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import java.sql.Date;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class Home extends AppCompatActivity {

    private List<myPlan>myPlanList=new ArrayList<>();

    private List<String>Data=new ArrayList<>();
    private ListView listView;
    private myPlanAdapter adapter;
    private MyDatabaseHelper dbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        dbHelper=new MyDatabaseHelper(this,"Records.db",null,2);
        Button plan=(Button)findViewById(R.id.myPlan);
        Button collection =(Button)findViewById(R.id.myCollection);
        Button record=(Button)findViewById(R.id.myRecord);


        plan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Toast.makeText(Home.this,"我的计划",Toast.LENGTH_SHORT).show();


                plan.setEnabled(false);
                collection.setEnabled(true);
                record.setEnabled(true);

            }
        });

        collection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {



                Toast.makeText(Home.this,"我的收藏",Toast.LENGTH_SHORT).show();
                plan.setEnabled(true);
                collection.setEnabled(false);
                record.setEnabled(true);

                /*
                Data.clear();
                SQLiteDatabase db=dbHelper.getWritableDatabase();
                Cursor cursor=db.query("Collection",null,null,null,null,null,null);
                if (cursor.moveToFirst())
                {
                    do {
                        String name=cursor.getString(cursor.getColumnIndex("name"));
                        Data.add(name);


                    }while (cursor.moveToNext());

                }
                cursor.close();
                ArrayAdapter<String>adapter1=new ArrayAdapter<String>(Home.this, android.R.layout.simple_list_item_1,Data);
                listView.setAdapter(adapter1);
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        String name=Data.get(position);
                        Intent intent=new Intent(Home.this,Introduce.class);
                        intent.putExtra("extra_data",name);
                        startActivity(intent);
                    }
                });*/

            }
        });

        record.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                Toast.makeText(Home.this,"我的游记",Toast.LENGTH_SHORT).show();
                plan.setEnabled(true);
                collection.setEnabled(true);
                record.setEnabled(false);


            }
        });


    }


    public void initPlans()
        {
            myPlanList.clear();
            myPlan plan1=new myPlan("plan1","","","");
            myPlanList.add(plan1);
            myPlan plan2=new myPlan("plan2","","","");
            myPlanList.add(plan2);

        }

    @Override
    protected void onPause() {
        super.onPause();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}